fix(database): link entity extenders at boot so companions hydrate during HTTP requests#74
Conversation
…ring HTTP requests EntityMetadataFactory is now a singleton and a boot callback discovers all entity classes and calls linkExtendersFrom() so extender metadata is populated before any repository hydration occurs. Previously linkExtenders() was only called from CLI migration commands, leaving companions unattached at runtime. Closes marko-php#73 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add @throws EntityException|MissingPrimaryKeyException|ReflectionException - Promote ReflectionException import - Use === [] for empty array check - Add blank lines between logical blocks for readability - Apply phpcbf multi-line call formatting to new tests Co-Authored-By: Michał Biarda <1135380+michalbiarda@users.noreply.github.com> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
7313833 to
52d5f29
Compare
|
Thanks @michalbiarda — this is a really important fix. The root cause analysis is spot-on: The two-part fix is exactly right:
I particularly like that Maintainer changesSmall style polish to match conventions in the rest of the file:
Rebased onto current Follow-up considerationRunning |
Summary
EntityMetadataFactorywas not registered as a singleton — every resolution created a fresh instance with an empty cachelinkExtenders()was only called fromSchemaRegistry::registerEntities(), which is invoked exclusively by CLI migration commands (DiffCommand,MigrateCommand)$metadata->extenderswas always[], soEntityHydratornever attached companion entitiesFix
EntityMetadataFactoryas a singleton inmodule.phpbootcallback that discovers all entity classes across vendor, modules, and app, then callslinkExtendersFrom()to populate the extender map once at startuplinkExtendersFrom()throws a loudEntityExceptionif an extender references a parent class that cannot be autoloaded, rather than silently ignoring the misconfigurationTest plan
linkExtendersFromscans entity classes and links extenders to their parentslinkExtendersFromignores entities withoutextendslinkExtendersFromthrowsEntityExceptionwhen an extender's parent class cannot be autoloadedcomposer testCloses #73
🤖 Generated with Claude Code